#include "stepthroughwidget.h"
#include "ui_stepthroughwidget.h"
#include <QtDebug>
#include "serialportset.h"
stepThroughWidget::stepThroughWidget(QWidget *parent) :
    QWidget(parent),
    ui(new Ui::stepThroughWidget)
{
    ui->setupUi(this);
    this->setWindowTitle("单步调试");
    initSwitchButton();
    this->setWindowModality(Qt::ApplicationModal);
}

stepThroughWidget::~stepThroughWidget()
{
    delete ui;
}
void stepThroughWidget::initSwitchButton()
{
    QList<SwitchButton *> tbtns = ui->groupBox->findChildren<SwitchButton *>();
    foreach (SwitchButton *btn, tbtns)
    {
        btn->setText("关", "开");
        connect(btn, SIGNAL(checkedChanged(bool)), this, SLOT(switchClick(bool)));
    }
}

void stepThroughWidget::switchClick(bool flag)
{
//    QToolButton *b = (QToolButton *)sender();
    SwitchButton *btn = (SwitchButton *)sender();
    if(btn->objectName() == "widget")
    {
        if(flag)
        {
            serialPortSet::Instance()->send01on();
        }
        else
        {
            serialPortSet::Instance()->send01off();
        }
    }
    else if(btn->objectName() == "widget_2")
    {
        if(flag)
        {
            serialPortSet::Instance()->send02on();
        }
        else
        {
            serialPortSet::Instance()->send02off();
        }
    }
    else if(btn->objectName() == "widget_3")
    {
        if(flag)
        {
            serialPortSet::Instance()->send03on();
        }
        else
        {
            serialPortSet::Instance()->send03off();
        }
    }
    else if(btn->objectName() == "widget_4")
    {
        if(flag)
        {
            serialPortSet::Instance()->send04on();
        }
        else
        {
            serialPortSet::Instance()->send04off();
        }
    }
    else if(btn->objectName() == "widget_5")
    {
        if(flag)
        {
            serialPortSet::Instance()->send05on();
        }
        else
        {
            serialPortSet::Instance()->send05off();
        }
    }
    else if(btn->objectName() == "widget_6")
    {
        if(flag)
        {
            serialPortSet::Instance()->send06on();
        }
        else
        {
            serialPortSet::Instance()->send06off();
        }
    }
    else if(btn->objectName() == "widget_7")
    {
        if(flag)
        {
            serialPortSet::Instance()->send07on();
        }
        else
        {
            serialPortSet::Instance()->send07off();
        }
    }
    else if(btn->objectName() == "widget_8")
    {
        if(flag)
        {
            serialPortSet::Instance()->send08on();
        }
        else
        {
            serialPortSet::Instance()->send08off();
        }
    }
    else if(btn->objectName() == "widget_9")
    {
        if(flag)
        {
            serialPortSet::Instance()->send09on();
        }
        else
        {
            serialPortSet::Instance()->send09off();
        }
    }
}
